package javatunes;
import java.util.ArrayList;


public class itunesplaylistmaker {
	public static void main (String[] args) throws Exception {
		String name=itunesplaylistmaker.class.getName();
		if (args.length!=0) {
			String usage="usage: java "+name+" [genre] [artist] [album] [title] [mode] [basedir]\n";
			usage+="\twhere [field] is in the form field=value and [mode] is either playlist or display\n";
			usage+="If mode is playlist, then you need to specify a basepath (the root directory of the ipod)\n\n";
			usage+="eg, to search for 'Come By Me' by 'Harry Connick Junior' to output a playlist:\n";
			usage+="\t java "+name+" artist='harry con' title='come by me mode=playlist basedir=e:\'";
			System.err.println(usage);
			System.exit(1);			
		}
		String artist="enigma";
		String album="viv";
		String title="";
		String genre="";
		String basedir=itunesdbreader.IPODDRIVE;
		String mode="playlist";
		long starttime=System.currentTimeMillis();
		
		ArrayList<mhit> results=itunesdbreader.search(new itunesdbreader().alltracks,new String[]{artist},new String[]{album},new String[]{title},new String[]{genre});
		//results=itunesdbreader.search(results,artist,album,"a",genre);
		//results=itunesdbreader.search(results,artist,album,"e",genre);
		//results=itunesdbreader.search(results,artist,"e",title,genre);
		
		if (results.size()==0) {
			System.err.println("No results!");
			System.exit(1);
		}
		if (mode.equals("playlist")) {
			System.out.println("[playlist]");
			for (int i=0;i<results.size();i++) {
				System.out.println("File"+(i+1)+"="+results.get(i).getFileName(basedir));	
			}
		}
		else {
			for (int i=0;i<results.size();i++) {
				System.out.println(results.get(i));	
			}
		}
		System.out.println("Time taken in millis: " + (System.currentTimeMillis()-starttime));
	}
	
}
